ADdata <- read.table("ADdata.txt") #读取实践3存储的文件
ADdata <- log2(ADdata+1) #对数化
ADdata2 <- t(ADdata) #对样本进行聚类需要转置,把行设置为样本
dist1 <- dist(ADdata2) #欧式距离计算样本间距离
dist2 <- dist(ADdata2, method = "manhattan") #曼哈顿距离计算样本间距离
dist3 <- 1- cor(ADdata) #根据pearson相关计算样本间距离(数据无需转置)
dist3 <- as.dist(dist3) #相关系数计算完成需要转换成距离矩阵
AD = hclust(dist1,method = 'average')#层次聚类
plot(AD,hang = 0.5,cex=.4)
AD = hclust(dist2,method = 'average')#层次聚类
plot(AD,hang = 0.5,cex=.4)
AD = hclust(dist3,method = 'average')#层次聚类
plot(AD,hang = 0.5,cex=.4)
pdf('ADdatatree.pdf')#绘制树状图
plot(AD,hang = 0.5,cex=.4)
dev.off()